package automateWebElements;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class StaticDropDownWithSelect {
    public static void main(String[] args) {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("https://rahulshettyacademy.com/dropdownsPractise/");
        //select dropdown with select tag
        WebElement staticDropdown = driver.findElementByXPath("//*[@id=\'ctl00_mainContent_DropDownListCurrency\']");
        Select dropdown = new Select(staticDropdown);
        dropdown.selectByIndex(3);
        System.out.println(dropdown.getFirstSelectedOption().getText());
        dropdown.selectByVisibleText("AED");
        System.out.println(dropdown.getFirstSelectedOption().getText());
        dropdown.selectByValue("INR");
        System.out.println(dropdown.getFirstSelectedOption().getText());

//        handle passengers dropdown and increase adult value
        driver.findElementByXPath("//*[@id=\'divpaxinfo\']").click();

        for (int i = 0; i < 5; i++) {
            driver.findElementByXPath("//*[@id=\'hrefIncAdt\']").click();
        }
        driver.findElementByXPath("//*[@id=\'btnclosepaxoption\']").click();

//        Play with passengers dropdown
        driver.findElementByXPath("//*[@id=\'divpaxinfo\']").click();

        for (int i = 0; i < 3; i++) {
            driver.findElementByXPath("//*[@id=\'hrefDecAdt\']").click();
            System.out.println(driver.findElementByXPath("//*[@id=\'hrefDecAdt\']").getText());
        }

        //increase child with 2
        for (int i = 0; i < 2; i++) {
            driver.findElementByXPath("//*[@id=\'hrefIncChd\']").click();
            System.out.println(driver.findElementByXPath("//*[@id=\'hrefIncChd\']").getText());
        }
        driver.findElementByXPath("//*[@id=\'btnclosepaxoption\']").click();
        System.out.println("Selection Done");

    }
}
